from PyQt5.QtCore import QThread, pyqtSignal

from common.to_shp import ToShp


class SHPThread(QThread):
    log = pyqtSignal(str, str, int)

    def __init__(self):
        super().__init__()
        self.filedir = None
        self.saveFile = None
        self.columns = None
        self.element_type = None

    def run(self):
        shp = ToShp(self.filedir, self.saveFile, self.columns, **self.kwargs)
        for xlsx, status, schedule in shp.run(self.element_type):
            self.log.emit(xlsx, status, schedule)

    def setValue(
            self,
            filedir: str,
            saveFile: str,
            columns: list,
            element_type: str = 'line',
            **kwargs
    ):
        self.filedir = filedir
        self.saveFile = saveFile
        self.columns = columns
        self.element_type = element_type
        self.kwargs = kwargs
